home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
clsres1a
/
clsresiz.cls
next >
Wrap
Text File
|
1999-09-04
|
16KB
|
309 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsResize"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' ======================================================================================== '
' Component : clsResize Created : 01/05/1999 '
' File Name : clsResize.cls Author : A D Moss '
' '
' Purpose : Resize and Reposition all controls on a Form. '
' ======================================================================================== '
' Copyright ⌐ 1999 - Adam David Moss - All Rights Reserved '
' '
' ======================================================================================== '
' '
Option Explicit
' ======================================================================================== '
' API Declarations. '
' ======================================================================================== '
Private Declare Function LockWindowUpdate Lib "user32.dll" (ByVal hwndLock As Long) As Long
' ======================================================================================== '
' Constant Declarations. '
' ======================================================================================== '
Private Const SSTAB_DIALOG_OFFSET As Long = 75000
Private Const SSTAB_TYPE_NAME As String = "SSTAB"
Private Const ResizeRepositionCommand As String = "@"
Private Const ResizeRepositionLeft As String = "L"
Private Const ResizeRepositionTop As String = "T"
Private Const ResizeRepositionWidth As String = "W"
Private Const ResizeRepositionHeight As String = "H"
' ======================================================================================== '
' Type Declarations. '
' ======================================================================================== '
Private Type ControlPosition
ControlInstance As Control 'Reference to the control instance.
OriginalLeft As Long 'Original Left position of the Control.
OriginalTop As Long 'Original Top position of the Control.
OriginalWidth As Long 'Original Width of the Control.
OriginalHeight As Long 'Original Height of the Control.
End Type
' ======================================================================================== '
' Enumeration Declarations. '
' ======================================================================================== '
' ======================================================================================== '
' Event Declarations. '
' ======================================================================================== '
' ======================================================================================== '
' Public Variable Declarations. '
' ======================================================================================== '
' ======================================================================================== '
' Private Variable Declarations. '
' ======================================================================================== '
Private m_SourceForm As Form 'The form to be resized.
Private m_FormWidth As Long 'Original form width.
Private m_FormHeight As Long 'Original form height.
Private m_Controls() As ControlPosition 'Array for storing control information.
Private m_IsFirstResize As Boolean 'Flag indicating first resize.
' ======================================================================================== '
' Routine : Class_Initialize Created : 01/05/1999 '
' Scope : Private Author : A D Moss '
' Description : Constructor used when an instance of this class is created. '
' ======================================================================================== '
Private Sub Class_Initialize()
Set m_SourceForm = Nothing
m_IsFirstResize = True
End Sub
' ======================================================================================== '
' Routine : Class_Terminate Created : 01/05/1999 '
' Scope : Private Author : A D Moss '
' Description : Destructor used when an instance of this class is destroyed. '
' ======================================================================================== '
Private Sub Class_Terminate()
Erase m_Controls
Set m_SourceForm = Nothing
End Sub
' ======================================================================================== '
' Routine : SourceForm (Get) Created : 01/05/1999 '
' Scope : Public Author : A D Moss '
' Description : Return the Form currently being used by an instance of this class. '
' ======================================================================================== '
Public Property Get SourceForm() As Form
Set SourceForm = m_SourceForm
End Property
' ======================================================================================== '
' Routine : SourceForm (Let) Created : 01/05/1999 '
' Scope : Public Author : A D Moss '
' Description : Set the Form to be used by an instance of this class. '
' ======================================================================================== '
Public Property Let SourceForm(New_SourceForm As Form)
Set m_SourceForm = New_SourceForm
End Property
' ======================================================================================== '
' Routine : SizeFormToScreen Created : 01/05/1999 '
' Scope : Public Author : A D Moss '
' Description : Size the Form to n Percent of the Screen. '
' ======================================================================================== '
Public Sub SizeFormToScreen(Optional Percent As Byte = 100)
'Variable Declarations.
Dim FormHeight As Long, FormWidth As Long
'Check if the form has not been resized before.
If m_IsFirstResize Then
Call SaveInitialStates
End If
'Calculate the new height and width the form needs to be resized to, based on the current
'screen resolution.
FormHeight = Int(Screen.Height * (Percent / 100))
FormWidth = Int(Screen.Width * (Percent / 100))
'Use the Form that is to be resized.
With m_SourceForm
'Change the demensions and position of the form.
.Top = (Screen.Height - FormHeight) / 2
.Left = (Screen.Width - FormWidth) / 2
.Height = FormHeight
.Width = FormWidth
End With
'Resize all of the controls on the form.
Call ResizeControls
End Sub
' ======================================================================================== '
'